<?php
namespace Admin\Controller;
use Think\Controller;

class TalkController extends CommonController{
	/**
	 * 说说列表
	 */
	public function index(){
		$db = M('talk');
		$count = $db->count();
		$pagesize = 10;
		$Page = new \Think\Page($count,$pagesize);
		$limit = $Page->firstRow.','.$Page->listRows;
		$Page->setConfig('prev','上一页');
		$Page->setConfig('next','下一页');
		$Page->setConfig('first','首页');
		$Page->setConfig('last','第%TOTAL_PAGE%页');
		$Page->setConfig('header','<span class="rows">每页'.$pagesize.'条 共%TOTAL_PAGE%页,%TOTAL_ROW%条记录</span>');
		$Page->setConfig('theme','%FIRST% %UP_PAGE% %LINK_PAGE% %DOWN_PAGE% %END% %HEADER%');

		$this->talk = M('Talk')->limit($limit)->select();
		$this->page  = $Page->show();
		$this->display();
	}
	public function addTalk(){
		$this->display();
	}
	public function runAddTalk(){
		$data = array(
			'talk'	=>	I('post.editorValue'),
			'time'	=>	time()
			);
		$data['talk'] = stripslashes($data['talk']);
		if(M('Talk')->add($data)){
			$this->success('发布说说成功',U('index'));
		}else{
			$this->error('发布说说失败');
		}
	}
	public function delTalk(){
		$id = I('get.id','','int');
		if(!M('talk')->delete($id)) $this->error('删除说说失败');
		redirect(U('index'));
	}
	public function edit(){
		$id = I('get.id','','int');
		$this->talk = M('talk')->where(array('id'=>$id))->field('id,talk')->find();
		$this->display();
	}
	public function editTalk(){
		$data = array(
			'id'	=>	I('post.id','','int'),
			'talk'	=>	I('post.editorValue')
			);
		$data['talk'] = stripslashes($data['talk']);
		if(M('talk')->save($data)){
			$this->success('修改成功',U('index'));
		}else{
			$this->error('修改失败');
		}
	}
	/**
	 * ueditor调用
	 */
	public function ueditor(){
		$data = new \Org\Util\Ueditor();
        echo $data->output();
	}

}